import yaml  # 导入时直接写的yaml，和安装的名字不一样

from conftest import BASE_DIR


def get_yaml_data(file_path):
    with open(file_path, encoding='utf-8') as f:
        return yaml.safe_load_all(f.read())


#覆盖写入
def write_yaml_data(file_path, data):
    with open(file_path, 'w',encoding='utf-8') as f:
        yaml.dump(data, f,default_flow_style=False,allow_unicode=True)


#追加写入
def append_list_to_yaml(file_path,data):
    with open(file_path, 'a',encoding='utf-8') as f:
        yaml.safe_dump(data, f, default_flow_style=False,allow_unicode=True)


if __name__ == '__main__':
    path=BASE_DIR+r"/config/list.yaml"
    # #读取
    # data = get_yaml_data(path)
    # print(data)

    data=[{"name":"张三","age":20},18]
    append_list_to_yaml(path,data)





